<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>C#</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="C#, tutorial, programming language, learn C#, .NET, Mono">
<meta name="description" content="This chapter of the C# tutorial describes the C# language.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<div class="content">

<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>



<h1>C#</h1>

<p>
In this part of the C# tutorial, we will introduce the 
C# programming language. 
</p>


<h2>Goal</h2>

<p>
The goal of this tutorial is to get you started with the C#
programming language. The tutorial covers the core of the C# language. 
Variables, arrays, control structures and other core features. 
It is not a complete coverage of the language. It is a quick, introductory
material. This tutorial uses command line compilers to build applications.
It does not cover graphical interface development, or visual IDEs. 
This tutorial focuses on the C# language; everything else is considered 
a distraction. 
</p>

<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* NewSquare */
google_ad_slot = "0364418177";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script>


<h2>C#</h2>

<p>
C# is a  modern, high-level, general-purpose, object-oriented programming language.
It is the principal language of the .NET framework. 
The design goals of the language were software robustness, durability and
programmer productivity. It can be used to create console applications, GUI applications,
web applications, both on PCs or embedded systems. It is a very popular language. 
Currently, it is one of the top 10 popular languages in the world. It was created 
on the Windows platform. The Mono project has created a clone for the Linux 
and Mac platforms. C# is a compiled language. The source code is compiled into 
executable (.exe) files, which are executed by the .NET platform.
</p>



<h2>Programming languages</h2>

<p>
There are currently several widely used programming languages. The following list is based on the 
<a href="http://www.tiobe.com/tpci.htm">TIOBE</a> Programming Community Index. The numbers are from August 2010. 
Note that these figures are only illustrative. 
</p>

<table width="400">
<tbody><tr>
<th>Position</th>
<th>Language</th>
<th>Ratings</th>
</tr>
<tr>
<td>1</td><td>Java</td><td>18%</td>
</tr>

<tr class="gray">
<td>2</td><td>C</td><td>17.9%</td>
</tr>
<tr>
<td>3</td><td>C++</td><td>9.7%</td>
</tr>
<tr class="gray">
<td>4</td><td>PHP</td><td>9.2%</td>
</tr>
<tr>
<td>5</td><td>Visual Basic</td><td>5.4%</td>
</tr>
<tr class="gray">
<td>6</td><td>C#</td><td>5%</td>
</tr>
<tr>
<td>7</td><td>Python</td><td>4.2%</td>

</tr>
<tr class="gray">
<td>8</td><td>Perl</td><td>3.4%</td>
</tr>
<tr>
<td>9</td><td>Objective C</td><td>3.2%</td>
</tr>
<tr class="gray">
<td>10</td><td>Delphi</td><td>2.4%</td>
</tr>

</tbody>
</table>

<p>
Java is the most widely used programming language. Java excels in 
creating portable mobile applications, programming various appliances 
and in creating enterprise applications. Every fourth application is 
programmed in C/C++. They are mainly used for creating operating systems 
and various desktop applications. C/C++ are the most widely used system 
programming languages. Most famous desktop applications were created in C++. 
May it be MS Office, Macromedia Flash, Adobe Photoshop or 3D Max. 
These two languages also dominate the game programming business. 
</p>

<p>
PHP dominates over the Web. While Java is used mainly by large organizations, 
PHP is used by smaller companies and individuals. 
</p>

<p>
Visual Basic represents the popularity of rapid application development 
and the dominance of Microsoft. 
</p>

<p>
The C# was planned to be the next big language. It should compete 
mainly with Java and C/C++ languages.
</p>

<p>
Python and PERL are popular scripting languages 
and close competitors. 
</p>

<p>
The popularity of the Objective C stems from Mac 
and their innovative appliances.
</p>

<p>
Deplhi is a popular RAD development tool.
</p>


<h2>Compiling</h2>

<p>
There are two prominent C# compilers. The Microsoft C# compiler and
the Mono C# compiler. 
</p>

<p>
<b>Linux</b> On Linux, we need to install the Mono C# compiler. 
It is called <b>gmcs</b> for C# 3.0 profile and <b>dmcs</b>
for the C# 4.0 profile. To install the Mono C# compiler, we must
install the Mono platform.
</p>

<pre>
$ gmcs simple.cs
$ ./simple.exe 
This is C#
</pre>

<p>
We compile and run a simple C# program on Linux. 
</p>

<hr class="btm">

<p>
<b>Windows</b> On Windows, we have two basic options. Either use the command line
compiler or use some version of the Visual Studio. The .NET framework is already 
installed on many versions of Windows OS. If not, we download it and install it
from the microsoft.com website. 
</p>

<p>
On my system, the .NET framework was installed on C:\WINDOWS\Microsoft.NET\Framework\v3.5.
Here we find the csc.exe file, which is a compiler of the C# language. 
</p>

<pre>
C:\programming\csharp>C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe simple.cs
C:\programming\csharp>simple.exe
This is C#
</pre>

<p>
We compile and run a simple C# program on Windows. 
</p>


<p>
Another option is to use e.g. Visual Studio C# Express Edition.
We create a new project. Select File/New Project
or click Ctrl+N. Select Console application. 
</p>

<br>
<img src="/img/lang/csharp/console.png" alt="Console application">
<div class="figure">Figure: Console application</div>
<br>

<p>
To run an example, click <b>Ctrl + F5</b>. 
</p>

<h2>Sources</h2>

<p>
The following sources were used to create this tutorial:
</p>

<ul>
<li><a href="http://www.msdn.com">msdn.com</a></li>
<li><a href="http://www.wikipedia.org">wikipedia.org</a></li>
<li><a href="http://www.stackoverflow.com">stackoverflow.com</a></li>
<li>C# Language specification</li>
</ul>


<p>
In this part of the C# tutorial, we have introduced the C# language. 
</p>


<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>

<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified October 12, 2010  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>
